package com.jcl.recruit.api.crawler.controller;

import com.jcl.core.common.page.PageResult;
import com.jcl.core.resp.ApiResponse;
import com.jcl.core.security.CrawlerUserToken;
import com.jcl.core.utils.StringUtils;
import com.jcl.recruit.channel.vo.ChannelResumeParamInfo;
import com.jcl.recruit.crawler.service.CrawlerResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CrawlerResumeDownloadController
 * @Description TODO
 * @Author yyliu
 * @Date 2018/10/22 10:28
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/crawler")
public class CrawlerResumeDownloadController {

    @Autowired
    private CrawlerResumeService      crawlerResumeService;

    @RequestMapping(value = "/resume/download/list", method = {RequestMethod.GET})
    public ApiResponse downloadResumeList(String corpCode, String source, Integer pageSize){

        if(StringUtils.isEmpty(corpCode) && StringUtils.isEmpty(source)){

            return ApiResponse.error("param is lose !");
        }

        PageResult data = crawlerResumeService.downloadResumeList(corpCode, source, pageSize);

        return ApiResponse.success(data);
    }

    @RequestMapping(value = "/resume/complete", method = {RequestMethod.GET, RequestMethod.POST})
    public ApiResponse completeResume(@RequestBody ChannelResumeParamInfo entity){

        if(StringUtils.isEmpty(entity.getTenantId())){
            return ApiResponse.error("param 'tenantId' is lose !");
        }
        CrawlerUserToken userToken = null;

        userToken = CrawlerUserToken.decodeTenantId(entity.getTenantId());
        if(null == userToken){
            return ApiResponse.error("param 'tenantId' is error !");
        }
        String corpCode = userToken.getCorpCode();
        String userId = userToken.getUserId();
        String resumeId = userToken.getResumeId();

        crawlerResumeService.completeResume(corpCode, userId, resumeId, entity);
        return ApiResponse.success("SUCCESS");
    }

    @RequestMapping(value = "/resume/complete/test", method = {RequestMethod.GET, RequestMethod.POST})
    public ApiResponse completeResumeTest(String resumeId){


        String corpCode = "JCL0000002";
        String userId = "4";

        crawlerResumeService.completeResume(corpCode, userId, resumeId, null);
        return ApiResponse.success("SUCCESS");
    }


}
